package pl.edu.wsinf.lukaszwalczak.emailclient.controller;

import java.util.Map;
import javax.inject.Inject;
import org.springframework.stereotype.Component;
import pl.edu.wsinf.lukaszwalczak.emailclient.pojo.Contact;
import pl.edu.wsinf.lukaszwalczak.emailclient.repository.ContactRepository;
import pl.edu.wsinf.lukaszwalczak.emailclient.view.ContactCreateView;

/**
 *
 * @author Łukasz
 */
@Component
public class ContactCreateController {

    @Inject
    private ContactCreateView view;
    @Inject
    private ContactListController contactListController;
    @Inject
    private ContactRepository contactRepository;

    public void showWindow() {
        view.show();
    }

    public void createContact(Map<String, String> values) {
        Contact contact = new Contact();
        contact.setName(values.get("name"));
        contact.setSurname(values.get("surname"));
        contact.setLabel(values.get("label"));
        contact.setEmail(values.get("email"));
        contact.setPhoneNumber(values.get("phone"));
        contact.setAdress(values.get("address"));
        contactRepository.save(contact);
        contactListController.loadList();
    }
}
